
package me.ak.sf.util;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class LevelTimer {
    
    public long total;
    public long startTime;
    public boolean running = false;
    public ActionListener finishListener;
    
    public LevelTimer(long time, ActionListener run) {
        total = time;
        finishListener = run;
    }
    
    public void start() {
        running = true;
        startTime = System.currentTimeMillis();
    }
    
    public long getTimePassed() {
        return System.currentTimeMillis()-startTime;
    }
    
    public void update() {
        if (running && System.currentTimeMillis()-startTime>=total) {
            running = false;
            finishListener.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "TimerEnd"));
        }
    }

}
